package com.develope.tree;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.develope.tree.db.DBHelper;

public class displayTree extends Activity implements OnClickListener {

	int from_Where_I_Am_Coming = 0;
	private DBHelper mydb;
	TextView user;
	TextView lo;
	TextView cay;
	TextView ngay;
	TextView ttrang;
	TextView kthuoc;
	TextView cdinh;
	TextView bche;
	TextView cao;
	TextView cv;
	TextView la;
	TextView canh;
	TextView lco;
	TextView sbenh;
	TextView doam;
	TextView tgian_bon;
	TextView lphan;
	TextView tgian_phun;
	TextView lthuoc;
	TextView tren_cay;
	TextView tren_luong;
	TextView danh_gia;
	TextView vde_khac;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_display_data);

		user = (TextView) findViewById(R.id.edtUser);
		lo = (TextView) findViewById(R.id.edtLo);
		cay = (TextView) findViewById(R.id.edtCay);
		ngay = (TextView) findViewById(R.id.edtDate);
		ttrang = (TextView) findViewById(R.id.edtTtang);
		kthuoc = (TextView) findViewById(R.id.edtKthuoc);
		cdinh = (TextView) findViewById(R.id.edtCdinh);
		bche = (TextView) findViewById(R.id.edtBche);
		cao = (TextView) findViewById(R.id.edtCao);
		cv = (TextView) findViewById(R.id.edtCv);
		la = (TextView) findViewById(R.id.edtLa);
		canh = (TextView) findViewById(R.id.edtCanh);
		lco = (TextView) findViewById(R.id.edtLco);
		sbenh = (TextView) findViewById(R.id.edtSau);
		doam = (TextView) findViewById(R.id.edtDoam);
		tgian_bon = (TextView) findViewById(R.id.edtTgianb);
		lphan = (TextView) findViewById(R.id.edtLphan);
		tgian_phun = (TextView) findViewById(R.id.edtTgianp);
		lthuoc = (TextView) findViewById(R.id.edtLthuoc);
		tren_cay = (TextView) findViewById(R.id.edtTrcay);
		tren_luong = (TextView) findViewById(R.id.edtTrluong);
		danh_gia = (TextView) findViewById(R.id.edtDgia);
		vde_khac = (TextView) findViewById(R.id.edtVde);

		mydb = new DBHelper(this);
		mydb.getReadableDatabase();
		mydb.getWritableDatabase();

		Button btnSave = (Button) findViewById(R.id.bt_save1);
		Button btnCancel = (Button) findViewById(R.id.bt_cancel);
		btnSave.setOnClickListener(this);
		btnCancel.setOnClickListener(this);

		Intent intent = getIntent();
		/*
		 * int Value = extras.getInt("id");
		 * 
		 * Tree tree = mydb.getTree(Value); String use = tree.getUser(); String
		 * lO = tree.getLo(); String ca = tree.getCay(); String nga =
		 * tree.getNgay(); String ttran = tree.getTtrang(); String bch =
		 * tree.getBche(); double caO = tree.getChCao(); double cV =
		 * tree.getCvi(); String lA = tree.getLa(); String can =
		 * tree.getTcanh(); String lc = tree.getLco(); String sben =
		 * tree.getSbenh(); String doa = tree.getDoam(); int tgian_b =
		 * tree.getTimebon(); double lpha = tree.getLuongbon(); int tgian_p =
		 * tree.getTimephun(); double lthuo = tree.getLuongphun(); double tren_c
		 * = tree.getSlcay(); double tren_l = tree.getSlluong(); String danh_gi
		 * = tree.getDgia(); String vde_kha = tree.getVdkhac();
		 * 
		 * user.setText(use); lo.setText(lO); cay.setText(ca);
		 * ngay.setText(nga); ttrang.setText(ttran); bche.setText(bch);
		 * cao.setText(Double.toString(caO)); cv.setText(Double.toString(cV));
		 * la.setText(lA); canh.setText(can); lco.setText(lc);
		 * sbenh.setText(sben); doam.setText(doa); tgian_bon.setText(tgian_b);
		 * lphan.setText(Double.toString(lpha)); tgian_phun.setText(tgian_p);
		 * lthuoc.setText(Double.toString(lthuo));
		 * tren_cay.setText(Double.toString(tren_c));
		 * tren_luong.setText(Double.toString(tren_l));
		 * danh_gia.setText(danh_gi); vde_khac.setText(vde_kha);
		 * 
		 * }
		 */
		
		Tree tree = (Tree) intent.getParcelableExtra(MainActivity.PAR);
		String use = tree.getUser();
		String lO = tree.getLo();
		String ca = tree.getCay();
		String nga = tree.getNgay();
		String ttran = tree.getTtrang();
		String kThuoc = tree.getKthuoc();
		String cDinh = tree.getCdinh();
		String bch = tree.getBche();
		double caO = tree.getChCao();
		double cV = tree.getCvi();
		String lA = tree.getLa();
		String can = tree.getTcanh();
		String lc = tree.getLco();
		String sben = tree.getSbenh();
		String doa = tree.getDoam();
		double lan_bon = tree.getTimebon();
		double lpha = tree.getLuongbon();
		double lan_phun = tree.getTimephun();
		double lthuo = tree.getLuongphun();
		double tren_c = tree.getSlcay();
		double tren_l = tree.getSlluong();
		String danh_gi = tree.getDgia();
		String vde_kha = tree.getVdkhac();

		user.setText(use);
		lo.setText(lO);
		cay.setText(ca);
		ngay.setText(nga);
		ttrang.setText(ttran);
		kthuoc.setText(kThuoc);
		cdinh.setText(cDinh);
		bche.setText(bch);
		cao.setText(Double.toString(caO));
		cv.setText(Double.toString(cV));
		la.setText(lA);
		canh.setText(can);
		lco.setText(lc);
		sbenh.setText(sben);
		doam.setText(doa);
		tgian_bon.setText(Double.toString(lan_bon));
		lphan.setText(Double.toString(lpha));
		tgian_phun.setText(Double.toString(lan_phun));
		lthuoc.setText(Double.toString(lthuo));
		tren_cay.setText(Double.toString(tren_c));
		tren_luong.setText(Double.toString(tren_l));
		danh_gia.setText(danh_gi);
		vde_khac.setText(vde_kha);

	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {

		case R.id.bt_save1:
			Tree tree = (Tree) getIntent().getParcelableExtra(MainActivity.PAR);
			mydb.insertTree(tree);
			setContentView(R.layout.activity_main);
			break;
		case R.id.bt_cancel:
			finish();
			break;

		default:
			break;
		}
	}
	
}
